
<template>
  <div>
    <Modal
      v-model="showBox"
      title="企业认证"
      :footer-hide="true"
      :mask-closable="false"
      @on-visible-change="vChange"
      width="505"
    >
      <div class="f_16 marginB20">用户手机：{{mobile}}</div>
      <Input
        type="text"
        v-model="company_name"
        placeholder="请输入公司名称"
        ref="company_name"
        class="marginB20"
        size="large"
        clearable
      >
        <Icon type="md-home" slot="prefix" />
      </Input>

      <!-- 1省+市+区；2省+市；3公司名认证专用：省+市+区 -->
      <!-- <YZ ref="YZ" :addObj="addObj" :type="3" class="marginB20" /> -->

      <Input
        type="text"
        v-model="email"
        placeholder="请输入邮箱"
        ref="email"
        class="marginB20"
        size="large"
        clearable
      >
        <Icon type="md-mail" slot="prefix" />
      </Input>

      <Row class="marginB20" :gutter="20">
        <Col span="16">
          <Input type="number" placeholder="短信验证码" v-model="code" ref="code" clearable size="large"
          onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
          >
            <Icon type="ios-chatboxes" slot="prefix" />
          </Input>
        </Col>
        <Col span="8">
        <!-- button 倒计时函数，要用jq处理，原因细说 -->
          <Button
            type="primary"
            size="large"
            long
            @click="goCodeFun"
            :disabled="btnDisabled"
            id="dDom"
          >获取验证码</Button>
        </Col>
      </Row>

      <div
        class="JC_img tran3 pointer textCenter cBlue pullLeft relative marginB20 marginR20"
        style="width:120px;"
      >
        <input type="file" ref="wj" accept="image/*" class="InputFileBox" @change="btnBWT($event)" />
        <Icon type="ios-add-circle-outline" class="marginB5" style="padding-top:30px;" size="30" />
        <div class="f_12">上传营业执照</div>
        <img
          :src="business_licence_path.file_url"
          v-show="$app.judgeData(business_licence_path.file_url)"
          class="InputShowImg cover"
        />
      </div>
      <div class="marginB10 cRed">* 请上传 jpg 或 png 图片格式</div>
      <Button type="info" size="small" v-show="$app.judgeData(business_licence_path.file_url)" @click="$app.openWindow(business_licence_path.file_url)">
        <Icon type="md-image" size="14" class="relative marginR5"  />查 看
      </Button>
      <div class="clearBoth"></div>


      <Button type="primary" class="marginB10" size="large" long @click="goFun">确 定</Button>
    </Modal>
  </div>
</template>



<script>
// import YZ from "@$@/_service/yZ";
export default {
  name: "companyGo",
  components: {
    // YZ
  },
  data() {
    let data = {

      // 弹框是否显示
      showBox: false,
      mobile: '',
      phoneOk: true, //true该手机 已注册存在系统
      companyAll:'',

      company_name: "",
      email: "",
      captcha: "", //图形 验证码
      code: "", //手机 验证码
      business_licence_path: {
        file_url: "",
        file_path: ""
      },

      // 获取验证码按钮
      btnDisabled: false
    };
    let add = {
      addObj: {
        people_province: "", //省份
        people_city: "", //城市
        people_area: "", //区
      }
    };
    return Object.assign(data, add);
  },

  created() {
    $ajax.userInfo(resData=>{
      this.mobile=resData.mobile;
    });

    $ajax.pInfo(resData => {
      this.companyAll=resData;
      
      if ($app.qBoxDo(this) && (!$app.judgeData(resData) || resData.state==0)) {
        this.showBox = true; //显示弹框
      }

    });
  },
  mounted() {},
  methods: {
    goCodeFun() {
      let that = this;
      let {
        mobile
      }=this;
      //2登录,3修改密码,4合伙人认证,5绑定邮箱
      $ajax.getCodeNn(that,'dDom',mobile,4);
    },
    //上传企业认证的执照
    btnBWT(e) {
      let file = e.target.files[0]; //选中的文件

      //格式判断
      $app.suffix.jpgPng(e,file,false,()=>{
        //1营业执照..... 21 企业认证(更多数字请看文档)
        $app.selectFileImage(null,null,file, 21, resData => {
          this.business_licence_path = resData;
          this.$refs['wj'].value='';//清空input file的值
        },()=>{
          this.$refs['wj'].value='';//清空input file的值
        }); 
      });

    },
    //提交
    goFun() {
      let that = this;
      let {
        $route: {
          query: { companyGo }
        },
        addObj:{
          people_province:province,
          people_city:city,
          people_area:area
        },
        companyAll,
        company_name,
        email,
        code,
        business_licence_path: { file_path: business_licence_path }
      } = that;



      if (!$app.judgeData(company_name)) {
        that.$Message.error({ content: "公司名称不能为空" });
        that.$refs["company_name"].focus();
      }

      // else if(!$app.judgeData(province) || !$app.judgeData(city) || !$app.judgeData(area)){
      //   that.$Message.error({ content: "请选择公司所在省市区" });
      // }

       else if (!$app.judgeData(email)) {
        that.$Message.error({ content: "邮箱不能为空" });
        that.$refs["email"].focus();
      } else if (!$app.mailCheck(email)) {
        that.$Message.error({ content: "邮箱格式错误，勿含空格等特殊字符" });
        that.$refs["email"].focus();
      } else if (!$app.judgeData(code)) {
        that.$Message.error({ content: "验证码不能为空" });
        that.$refs["code"].focus();
      } else if (!$app.judgeData(business_licence_path)) {
        that.$Message.error({ content: "请上传营业执照" });
      } else {
        //企业信息验证提交
        $ajax.cpAuth_YZ({
          province,
          city,
          area,
          company_name,
          email,
          business_licence_path,
          code
        },() => {
          if ($app.qBoxDo(this)) {//用户自己 被迫进来的
            //强制性更新
            $app.closeHadPage("accountInfo"); //更新完成关闭本页
          } else {//用户自己主动 进来的
            this.$parent.$emit('up_cAll');// 执行父亲的方法
            that.showBox = false;//隐藏弹框
          }
          
        });
      }
    },

    //弹框消失
    vChange(buEr) {
      let {
        $route: {
          query: { companyGo }
        },
        companyAll
      } = this;

      if (!buEr) {//关闭窗口
        


        this.company_name = "";
        this.email = "";
        this.captcha = ""; //图形 验证码
        this.code = ""; //手机 验证码
        this.business_licence_path = {
          file_url: "",
          file_path: ""
        };
        
        

      }
    }
  }
};
</script>

